/*
 * ImportRouteShapefileAttributesDialog.java
 *
 * Created on June 13, 2007, 10:08 PM
 *
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.fpdev.apps.admin.gui.dialogs;

import org.fpdev.util.gui.GUIFactory;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import org.fpdev.apps.admin.AdminClient;
import org.opengis.feature.type.AttributeType;

/**
 *
 * @author demory
 */
public class ImportRouteShpAttrDialog extends JDialog implements ActionListener {

  private boolean okClicked_;
  private JComboBox routeAttrSelect_,  directionAttrSelect_,  patternAttrSelect_;
  private JButton okBtn_,  cancelBtn_;

  public ImportRouteShpAttrDialog(AdminClient av, List<AttributeType> attrs) {
    super(av.getGUI(), "Specify Attributes", true);

    okClicked_ = true;

    routeAttrSelect_ = GUIFactory.newComboBox(200);
    directionAttrSelect_ = GUIFactory.newComboBox(200);
    patternAttrSelect_ = GUIFactory.newComboBox(200);

    for (AttributeType attr : attrs) { //int i = 1; i < attrs.length; i++) {
      routeAttrSelect_.addItem(attr.getName());
      directionAttrSelect_.addItem(attr.getName());
      patternAttrSelect_.addItem(attr.getName());
    }

    routeAttrSelect_.setSelectedIndex(5);
    directionAttrSelect_.setSelectedIndex(10);
    patternAttrSelect_.setSelectedIndex(7);

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
    JLabel l1 = new JLabel("Route ID Attribute");
    l1.setAlignmentX(LEFT_ALIGNMENT);
    topPanel.add(l1);
    routeAttrSelect_.setAlignmentX(LEFT_ALIGNMENT);
    topPanel.add(routeAttrSelect_);
    topPanel.add(Box.createVerticalStrut(5));
    JLabel l2 = new JLabel("Direction ID Attribute");
    l2.setAlignmentX(LEFT_ALIGNMENT);
    topPanel.add(l2);
    directionAttrSelect_.setAlignmentX(LEFT_ALIGNMENT);
    topPanel.add(directionAttrSelect_);
    topPanel.add(Box.createVerticalStrut(5));
    JLabel l3 = new JLabel("Pattern ID Attribute");
    l3.setAlignmentX(LEFT_ALIGNMENT);
    topPanel.add(l3);
    patternAttrSelect_.setAlignmentX(LEFT_ALIGNMENT);
    topPanel.add(patternAttrSelect_);
    topPanel.add(Box.createVerticalStrut(15));

    okBtn_ = new JButton("OK");
    okBtn_.addActionListener(this);
    cancelBtn_ = new JButton("Cancel");
    cancelBtn_.addActionListener(this);

    JPanel btnRow = new JPanel();
    btnRow.setLayout(new BoxLayout(btnRow, BoxLayout.X_AXIS));
    btnRow.add(Box.createHorizontalGlue());
    btnRow.add(okBtn_);
    btnRow.add(Box.createHorizontalStrut(5));
    btnRow.add(cancelBtn_);
    btnRow.add(Box.createHorizontalGlue());

    btnRow.setAlignmentX(LEFT_ALIGNMENT);
    topPanel.add(btnRow);

    /*JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
    topPanel.setAlignmentX(LEFT_ALIGNMENT);
    mainPanel.add(topPanel);
    mainPanel.add(Box.createVerticalStrut(6));
    btnRow.setAlignmentX(CENTER_ALIGNMENT);
    mainPanel.add(btnRow);*/

    topPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(topPanel);

    this.pack();
    this.setLocation((av.getGUI().getWidth() / 2) - getWidth() / 2 + av.getGUI().getX(),
            (av.getGUI().getHeight() / 2) - getHeight() / 2 + av.getGUI().getY());
    setVisible(true);

  }

  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == okBtn_) {
      okClicked_ = true;
    }
    this.setVisible(false);
  }

  public boolean okClicked() {
    return okClicked_;
  }

  public int getSelectedRouteIndex() {
    return routeAttrSelect_.getSelectedIndex() + 1;
  }

  public int getSelectedDirectionIndex() {
    return directionAttrSelect_.getSelectedIndex() + 1;
  }

  public int getSelectedPatternIndex() {
    return patternAttrSelect_.getSelectedIndex() + 1;
  }
}
